package com.alibaba.citrus.cr.unified.inventory.functions.invoiceOrder;

import java.util.List;

import com.epoch.app.crunifiedinventory.dto.request.InvoiceOrderCreateRequest;
import com.google.common.collect.Lists;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

@Data
public class InvoiceOrderFactory {
    public static InvoiceOrderEntity create(InvoiceOrderCreateRequest request) {
        InvoiceOrderEntity entity = new InvoiceOrderEntity();

        List<InvoiceOrderDetailEntity> detailEntityList = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(request.getDetailList())) {
            request.getDetailList().forEach(invoiceOrderDetailCreateDTO -> {
                detailEntityList.add(InvoiceOrderDetailFactory.create(request, invoiceOrderDetailCreateDTO));
            });
        }
        entity.setInvoiceOrderDetailEntityList(detailEntityList);

        entity.createInvoiceOrderSDO(request);
        return entity;
    }
}
